using System;
using System.Net.Configuration;
using System.Text;
using Sirenix.OdinInspector;
using Sirenix.Serialization;

namespace BTEditor
{
    [BTDecorator]
    public class TimeMin : Decorator
    {
        public override Type GetNodeType()
        {
            return typeof(NPBehave.TimeMin);
        }

        public override ErrorType GetIsVaild()
        {
            return BelongNode.IsHaveChild ? ErrorType.None : ErrorType.Error;
        }

        protected override void DealField(StringBuilder sb)
        {
            sb.Append($"{limit.ToArgs()},");
            if (argsCountType == ArgsCountType.Two || argsCountType == ArgsCountType.Three)
            {
                sb.Append($"{waitOnFailure.ToArgs()},");
                if (argsCountType == ArgsCountType.Three)
                {
                    sb.Append($"{randomVariance.ToArgs()},");
                }
            }
        }

        public override int ShowArgsMask => (int) (ArgsCountType.Two | ArgsCountType.Three | ArgsCountType.One);

        [InfoBox("run the given decoratee. If the decoratee finishes sucessful before the limit with randomVariation time is reached, the decorator will wait until the limit is reached and then stop the execution with the result of the Decoratee. If waitOnFailure is true, the decoratee will also wait when the decoratee fails.","infoBox")]
        [Title("是否显示节点注释")]
        [LabelText("显示节点注释 ： ")]
        public bool infoBox;

        [EnumButton("ShowArgsMask")]
        [HideLabel] 
        [Title("参数选择")]
        public ArgsCountType argsCountType;
        
        [HideLabel] [Title("最少时间")]   [OdinSerialize]
        public float limit = 0.0F;
        
        [LabelText("等待超时处理")] [Title("等待超时处理")]   [OdinSerialize]
        [EnableIf("argsCountType",ArgsCountType.Two)]
        [InfoBox(" If waitOnFailure is true, the decoratee will also wait when the decoratee fails.")]
        public bool waitOnFailure = false;
                
        [HideLabel] [Title("执行差异")] 
        [OdinSerialize]
        [EnableIf("argsCountType",ArgsCountType.Three)]
        public float randomVariance = 0;
    }
}